# -*- coding: utf-8 -*-
"""
@Author  : Klaus
@Time    : 2022-05-18 0018 14:17

"""
import collections
from pprint import pprint
from random import choice

Card = collections.namedtuple('Card', ['rank', 'suit'])


class FrenchDeck:
    ranks = [str(n) for n in range(2, 11)] + list('JQKA')  # 生成一副扑克牌的所有牌面，不包含花色,大小王，从2到11，再加上J,Q,K,A
    suits = 'spades diamonds clubs hearts'.split()  # 生成扑克四种花色

    def __init__(self):
        self._cards = [Card(rank, suit) for suit in self.suits for rank in self.ranks]

    def __len__(self):
        return len(self._cards)

    def __getitem__(self, position):
        return self._cards[position]


if __name__ == '__main__':
    bee_card = Card('7', 'diamond')
    pprint(bee_card)

    deck = FrenchDeck()
    pprint(len(deck))
    pprint(deck[0])
    pprint(choice(deck))  # 随机获取一张带花色的牌
